<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<p id="arrold">11,2,5,100,68,44,48</p>
		<p>
			<input type="button" value="升序" onclick="asc()">
			<input type="button" value="降序" onclick="desc()">
			<input type="button" value="求和" onclick="sum()">
			<input type="button" value="反转" onclick="reversal()">
			<input type="button" value="包含100" onclick="contain()">
			<input type="button" value="添加" onclick="add()">
		</p>
		<p id="arrnew"></p>

		<script>
			var arr = [11, 2, 5, 100, 68, 44, 48];
			var old = document.getElementById('arrold');
			old.innerHTML = arr;
			var newarr = document.getElementById('arrnew');

			function asc() {
				newarr.innerHTML = arr.sort(function(a, b) {
					return a - b
				});
			}

			function desc() {
				newarr.innerHTML = arr.sort(function(a, b) {
					return b - a
				});
			}

			function sum() {
				var sum = 0;
				for(var i in arr) {
					sum = sum + arr[i];
				}
				arrnew.innerHTML = sum;
			}

			function reversal() {
				for(var i = arr.length - 1; i >= 0; i--) {
					document.write(arr[i] + ',' + '');
				}
			}

			function contain() {
				for(var i = 0; i < arr.length; i++) {
					if(arr[i] == 100) {
						var a = i + 1;

						arrnew.innerHTML = a;
						break;
					}
				}
			}

			function add() {
				arr.splice(2, 0, "1", "2", "3");
				arrnew.innerHTML = arr;

			}
		</script>
	</body>

</html>